/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.personassessmentinfo.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.modules.personassessmentinfo.entity.PersonAssessmentInfo;
import com.fosung.frame.modules.personassessmentinfo.service.PersonAssessmentInfoService;

/**
 * 党员考核积分设置Controller
 * @author wu
 * @version 2017-08-30
 */
@Controller
@RequestMapping(value = "${adminPath}/personassessmentinfo/personAssessmentInfo")
public class PersonAssessmentInfoController extends BaseController {

	@Autowired
	private PersonAssessmentInfoService personAssessmentInfoService;
	
	@ModelAttribute
	public PersonAssessmentInfo get(@RequestParam(required=false) String id) {
		PersonAssessmentInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = personAssessmentInfoService.get(id);
		}
		if (entity == null){
			entity = new PersonAssessmentInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("personassessmentinfo:personAssessmentInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(PersonAssessmentInfo personAssessmentInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PersonAssessmentInfo> page = personAssessmentInfoService.findPage(new Page<PersonAssessmentInfo>(request, response), personAssessmentInfo); 
		model.addAttribute("page", page);
		return "modules/personassessmentinfo/personAssessmentInfoList";
	}

	@RequiresPermissions("personassessmentinfo:personAssessmentInfo:view")
	@RequestMapping(value = "form")
	public String form(PersonAssessmentInfo personAssessmentInfo, Model model) {
		model.addAttribute("personAssessmentInfo", personAssessmentInfo);
		return "modules/personassessmentinfo/personAssessmentInfoForm";
	}

	@RequiresPermissions("personassessmentinfo:personAssessmentInfo:edit")
	@RequestMapping(value = "save")
	public String save(PersonAssessmentInfo personAssessmentInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, personAssessmentInfo)){
			return form(personAssessmentInfo, model);
		}
		personAssessmentInfoService.save(personAssessmentInfo);
		addMessage(redirectAttributes, "保存党员考核积分设置成功");
		return "redirect:"+Global.getAdminPath()+"/personassessmentinfo/personAssessmentInfo/?repage";
	}
	
	@RequiresPermissions("personassessmentinfo:personAssessmentInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(PersonAssessmentInfo personAssessmentInfo, RedirectAttributes redirectAttributes) {
		personAssessmentInfoService.delete(personAssessmentInfo);
		addMessage(redirectAttributes, "删除党员考核积分设置成功");
		return "redirect:"+Global.getAdminPath()+"/personassessmentinfo/personAssessmentInfo/?repage";
	}
	
	/**
	 * 跳转到党员积分说明
	 * @param homeApprove
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "toQueryPersonAssessmentInfo")
	public String toQueryPersonAssessmentInfo(HttpServletRequest request, HttpServletResponse response, Model model) {
		String orgId = request.getParameter("orgId");
		String mode = request.getParameter("mode");
		model.addAttribute("orgId", orgId);
		model.addAttribute("mode", mode);
		return "modules/approve/personAssessmentInfo";
	}
	
	/**
	 * 查看党员积分说明
	 * @param homeApprove
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "queryPersonAssessmentInfo")
	@ResponseBody
	public List<PersonAssessmentInfo> queryPersonAssessmentInfo(PersonAssessmentInfo personAssessmentInfo,  Model model) {
		List<PersonAssessmentInfo> list = personAssessmentInfoService.queryPersonAssessmentInfoList(personAssessmentInfo);
		return list;
	}

}